package com.lg.partition19;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/3/4 22:02
 */
public class P1802五倍经验日 {

    private static final int N = 1010;
    private static long[] f = new long[N];
    private static int[] w1 = new int[N], w2 = new int[N], v = new int[N];
    private static int n, m;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        for (int i = 1; i <= n; i++) {
            ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]), c = Integer.parseInt(ss[2]);
            w1[i] = a;
            w2[i] = b;
            v[i] = c;
        }
        for (int i = 1; i <= n; i++) {
            for (int j = m; j >= 0; j--) {
                //如果能打过，就决策是直接认输好还是打赢比较好；如果不能打过，只有直接认输，否则会丢失药
                if (j >= v[i]) f[j] = Math.max(f[j] + w1[i], f[j - v[i]] + w2[i]);
                else f[j] += w1[i];
            }
        }
        writer.write(((long) 5 * f[m]) + "\n");
        writer.flush();
    }
}
